package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/** 增强for循环 */
public class NewForDemo {
    public static void main(String[] args) {
        Collection c = new ArrayList();

        Collection<String> cc = new ArrayList<>();

        String[]array = {"one","two","three","four","five"};
        for (int i = 0;i < array.length;i++){
            System.out.print(" "+array[i]+" ");
        }
        System.out.println();
        for(String str:array){//str表示的就是数组中的每个元素
            System.out.print(" "+str+" ");
        }
        System.out.println();
        System.out.println("-----------------------------");

        Collection c2 = new ArrayList();
        c2.add("oen");
        c2.add("two");
        c2.add("three");
        c2.add("four");
        c2.add("five");
        Iterator it = c2.iterator();
        while (it.hasNext()){
            String str = (String) it.next();
            System.out.print(" "+str+" ");
        }
        System.out.println();
        for(Object obj : c2){
            String str = (String) obj;
            System.out.print(" "+str+" ");
        }



    }
}
